/**
 * 应用发开助手管理初始化
 */
var AppHelper = {
    id: "AppHelperTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
AppHelper.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '主键id', field: 'id', visible: false, align: 'center', valign: 'middle', sortable: true},
        {title: '名称', field: 'helperName', align: 'center', valign: 'middle', sortable: true},
        {title: '功能', field: 'helperFunc', align: 'center', valign: 'middle', sortable: true},
        {title: '类型', field: 'helperType', align: 'center', valign: 'middle', sortable: true},
        {title: '描述', field: 'helperDesc', align: 'center', valign: 'middle', sortable: true},
        {title: '排序', field: 'weight', align: 'center', valign: 'middle', sortable: true},
        {title: '链接', field: 'helperLink', align: 'center', valign: 'middle', sortable: true,
	    	formatter:function(value,row,index){
		    	if(value!==null){
		            return "<a href='"+value+"'"+"target="+"'_Blank'"+">"+value+"</a>";
		    	}else{
		            return "--";
		    	}
		    }
        },
    ];
};

/**
 * 检查是否选中
 */
AppHelper.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        AppHelper.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加应用发开助手
 */
AppHelper.openAddAppHelper = function () {
    var index = layer.open({
        type: 2,
        title: '添加应用发开助手',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Sys.backendPath + '/apphelper/to_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看应用发开助手详情
 */
AppHelper.openAppHelperDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '应用发开助手详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Sys.backendPath + '/apphelper/to_update/' + AppHelper.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除应用发开助手
 */
AppHelper.del = function () {
    if (this.check()) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/apphelper/delete", function (data) {
	            Sys.success("删除成功!");
	            AppHelper.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("appHelperId",AppHelper.seItem.id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除应用发开助手?",operation);
    }
};

/**
 * 查询应用发开助手列表
 */
AppHelper.search = function () {
    var queryData = {};
    queryData['helperName'] = $("#helperName").val();
    queryData['helperFunc'] = $("#helperFunc").val();
    queryData['helperType'] = $("#helperType").val();
    queryData['helperDesc'] = $("#helperDesc").val();
    queryData['helperLink'] = $("#helperLink").val();
    queryData['weight'] = $("#weight").val();
    AppHelper.table.refresh({query: queryData});
};

/**
 * 下载mui版本
 */
AppHelper.muidownload = function () {
	$("#muidownload").submit();
}

/**
 * 下载H5+版本
 */
AppHelper.h5download = function () {
	$("#h5download").submit();
}

/**
 * 下载应用开发包
 */
AppHelper.applicationdownload = function () {
	$("#applicationdownload").submit();
}

/**
 * 下载应用开发包
 */
AppHelper.toF7Design = function (url) {
	window.open(url);
}

$(function () {
    var defaultColunms = AppHelper.initColumn();
    var table = new BSTable(AppHelper.id, Sys.backendPath + "/apphelper/list", defaultColunms);
    table.setPaginationType("server");
    table.setSortName("weight");
    AppHelper.table = table.init();
});
